package cn.juque.jdfsystem.disruptor.event;

import cn.juque.common.base.DisruptorBody;
import cn.juque.common.disruptor.IBusinessEventService;
import cn.juque.jdfsystem.disruptor.bo.ConfigUpdateBodyBO;
import cn.juque.jdfsystem.task.ConfigInfoRefreshTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>ConfigUpdateDisruptorEventServiceImpl</li>
 * </ul>
 * @date 2023-01-11 17:42:15
 **/
@Slf4j
@Service("configUpdateDisruptorEventService")
public class ConfigUpdateDisruptorEventServiceImpl implements IBusinessEventService {

    public static final String BEAN = "configUpdateDisruptorEventService";

    @Resource
    private ConfigInfoRefreshTask configInfoRefreshTask;

    /**
     * 具体消费者的实现
     *
     * @param disruptorBody 消息体
     */
    @Override
    public void invoke(DisruptorBody disruptorBody) {
        if (disruptorBody instanceof ConfigUpdateBodyBO) {
            ConfigUpdateBodyBO bodyBO = (ConfigUpdateBodyBO) disruptorBody;
            log.info("根据节点【{}】通知需要刷新本地配置信息", bodyBO.getSendNode());
            this.configInfoRefreshTask.start(null);
        }
    }
}
